package org.boulderfoodrescue.webapp.shared;

import java.io.Serializable;

public class Location implements Serializable{
	private static final long serialVersionUID = -5625192602296160540L;
	/* Type info */
	public enum LocationType{Donor, Recipient}
	protected LocationType type;

	/* Database info */
	protected Long databaseKey;

	/*General Info */
	protected String name;
	protected String notes;

	/* Address Info */
	protected String streetAddress;
	protected String city;
	protected String state;
	protected String zipCode;
	protected Double latitude;
	protected Double longitude;

	/* The account that created the location */
	protected String creatorEmail;

	/* The contact info provided on creation */
	protected String contactName;
	protected String contactEmail;
	protected String contactPhone;

	/* Donor specific Infomration */
	public enum FoodType{Produce, PreparedFood, BakedGoods};
	private FoodType foodType;
	private Double ammountExpected;

	protected Location(){};

	public Location(LocationType type)
	{
		name = "";
		notes = "";
		streetAddress = "";
		city = "";
		state = "";
		zipCode = "";
		latitude = 0.0;
		longitude = 0.0;
		creatorEmail = "";
		contactName = "";
		contactPhone = "";
		this.type = type;
		switch(type)
		{
		case Donor:
			foodType = FoodType.Produce;
			ammountExpected = 0.0;
			break;
		case Recipient:
			break;
		}
	}

	public String firstLineOfAddress()
	{
		return streetAddress;
	}

	public String secondLineOfAddress()
	{
		StringBuilder sb = new StringBuilder();
		sb.append(city);
		sb.append(" ");
		sb.append(state);
		sb.append(", ");
		sb.append(zipCode+"");
		return sb.toString();
	}

	@Override
	public String toString(){
		return name;
	}

	public Long getDatabaseKey() {
		return databaseKey;
	}
	public void setDatabaseKey(Long databaseKey) {
		this.databaseKey = databaseKey;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public String getStreetAddress() {
		return streetAddress;
	}
	public void setStreetAddress(String streetAddress) {
		this.streetAddress = streetAddress;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getZipCode() {
		return zipCode;
	}
	public void setZipCode(String zip_code) {
		this.zipCode = zip_code;
	}
	public Double getLatitude() {
		return latitude;
	}
	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}
	public Double getLongitude() {
		return longitude;
	}
	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public String getContactName() {
		return contactName;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}

	public String getContactEmail() {
		return contactEmail;
	}

	public void setContactEmail(String contactEmail) {
		this.contactEmail = contactEmail;
	}

	public String getContactPhone() {
		return contactPhone;
	}

	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	public String getCreatorEmail() {
		return creatorEmail;
	}

	public void setCreatorEmail(String creatorEmail) {
		this.creatorEmail = creatorEmail;
	}

	public LocationType getType() {
		return type;
	}

	public void setType(LocationType type) {
		this.type = type;
	}

	public Long getTypeAsLong(){
		switch(type)
		{
		case Donor: return 0l;
		case Recipient: return 1l;
		}
		return -1l;
	}

	public void setTypeViaLong(Long value){
		switch(value.intValue())
		{
		case 0: type = LocationType.Donor;
		case 1: type = LocationType.Recipient;
		}
	}

	public FoodType getFoodType() {
		return foodType;
	}
	public void setFoodType(FoodType foodType) {
		this.foodType = foodType;
	}
	public Integer getFoodTypeAsInt()
	{
		switch(foodType)
		{
		case Produce: return 0;
		case PreparedFood: return 1;
		case BakedGoods: return 2;
		default: return -1;
		}
	}
	public void setFoodTypeFromInt(Long foodType)
	{
		switch(foodType.intValue())
		{
		case 0: this.foodType = FoodType.Produce;break;
		case 1: this.foodType = FoodType.PreparedFood; break;
		case 2: this.foodType = FoodType.BakedGoods; break;
		}
	}
	public Double getAmmountExpected() {
		return ammountExpected;
	}
	public void setAmmountExpected(Double ammountExpected) {
		this.ammountExpected = ammountExpected;
	}
}	
